﻿using System;
using System.Collections.Generic;
using System.Text;

namespace NetPs.Socket
{
    public static partial class SocketHepler
    {
        /// <summary>
        /// 推入
        /// </summary>
        /// <remarks>
        /// 推入全部数据。offset: 0, length: -1
        /// </remarks>
        public static void Enqueue(IQueueStream stream, byte[] block)
        {
            stream.Enqueue(block, 0, -1);
        }
        /// <summary>
        /// 推出
        /// </summary>
        /// <remarks>
        /// 推出全部数据。offset: 0, length: -1
        /// </remarks>
        public static int Dequeue(IQueueStream stream, byte[] block)
        {
            return stream.Dequeue(block, 0, -1);
        }

        /// <summary>
        /// 传输
        /// </summary>
        /// <remarks>
        /// 传输全部数据。offset: 0, length: -1
        /// </remarks>
        public static void Transport(IDataTransport tx, byte[] data) => tx.Transport(data, 0, -1);
        internal static bool LastEqual(byte[] bytes, byte val) { return bytes[bytes.Length - 1] == val; }
        public static byte[] CopyNew(byte[] bytes, int offset, int length)
        {
            length = offset + length;
            if (length > bytes.Length) length = bytes.Length;

            var size = length - offset;
            var outarr = new byte[size];
            for (size--, length --;size  >= 0; length--, size --)
                outarr[size] = bytes[length];
            return bytes;
        }
    }
}
